{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "a6c975c1",
   "metadata": {},
   "outputs": [],
   "source": [
    "#日期:week09\n",
    "课程:数据分析\n",
    "Author：周圳"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c3b16d23",
   "metadata": {},
   "source": [
    "# 1.数据获取"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "8414e24a",
   "metadata": {},
   "outputs": [],
   "source": [
    "url = 'https://api-c.liepin.com/api/com.liepin.searchfront4c.pc-search-job'"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "3dc380ad",
   "metadata": {},
   "source": [
    "* 请求方法： POST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e88d1ed3",
   "metadata": {},
   "outputs": [],
   "source": [
    "import requests,json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "2264230e",
   "metadata": {},
   "outputs": [],
   "source": [
    "payload = {\n",
    "  \"data\": {\n",
    "    \"mainSearchPcConditionForm\": {\n",
    "      \"city\": \"410\",\n",
    "      \"dq\": \"410\",\n",
    "      \"pubTime\": \"\",\n",
    "      \"currentPage\": 0,\n",
    "      \"pageSize\": 40,\n",
    "      \"key\": \"\",\n",
    "      \"suggestTag\": \"\",\n",
    "      \"workYearCode\": \"0\",\n",
    "      \"compId\": \"\",\n",
    "      \"compName\": \"\",\n",
    "      \"compTag\": \"\",\n",
    "      \"industry\": \"\",\n",
    "      \"salary\": \"\",\n",
    "      \"jobKind\": \"\",\n",
    "      \"compScale\": \"\",\n",
    "      \"compKind\": \"\",\n",
    "      \"compStage\": \"\",\n",
    "      \"eduLevel\": \"\"\n",
    "    },\n",
    "    \"passThroughForm\": {\n",
    "      \"scene\": \"init\",\n",
    "      \"skId\": \"\",\n",
    "      \"fkId\": \"\",\n",
    "      \"ckId\": \"wnabyvqio1y48ih09h7p1ucqoct6gfe8\",\n",
    "      \"suggest\": \"\"\n",
    "    }\n",
    "  }\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "e215ad25",
   "metadata": {},
   "outputs": [],
   "source": [
    "# headers = {\n",
    "#     'User-Agent':\"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/107.0.0.0 Safari/537.36\"\n",
    "# }"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "d7b1189a",
   "metadata": {},
   "outputs": [],
   "source": [
    "headers = {\n",
    "    'Accept': 'application/json, text/plain, */*',\n",
    "    'Accept-Encoding': 'gzip, deflate, br',\n",
    "    'Accept-Language': 'zh-CN,zh;q=0.9',\n",
    "    'Cache-Control': 'no-cache',\n",
    "    'Connection': 'keep-alive',\n",
    "    'Content-Length': '412',\n",
    "    'Content-Type': 'application/json;charset=UTF-8;',\n",
    "    'Cookie': 'inited_user=c8fbc4bc55b6e51a966d6a7b04560e2b; __uuid=1681904685651.21; __gc_id=dec84b24056047edae4ab20d0f3b552c; _ga=GA1.1.1262698532.1681904712; __tlog=1682508693416.34%7C00000000%7C00000000%7Cs_00_003%7Cs_00_003; XSRF-TOKEN=QPpeeqO4QQWdJqIco9nBJg; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1681904713,1682508703; acw_tc=2760829516825087007741276e1caa6c807a01cfcdc2c891680768c4e8d0e4; UniqueKey=6f683431aef475db6bc56763ae71c6f2; liepin_login_valid=0; lt_auth=7%2BlcaSMGzVnwtSXRj2MK5Kcb2Y3%2BU2jN8Stfh0xUht%2FoCPfk4P%2FmQAOHqLME%2BCoIqxkhJvUzMLb2N%2B3%2BwXRJ7kAW8FGnlpyutP2k1XYeTeVnHuyflMXuqsjQQ5wtrXo6ykpgn2si0HU%3D; access_system=C; user_roles=0; need_bind_tel=false; new_user=true; c_flag=d2d1cef45ed41589b63eda8f3d9bae3e; user_photo=5f8fa3a6f6d1ab58476f322808u.png; user_name=%E4%B8%AD%E6%96%B9%E6%B3%95; inited_user=c8fbc4bc55b6e51a966d6a7b04560e2b; imClientId=9e6702f76d03ac5a694a49467e3c9cd1; imId=9e6702f76d03ac5ac0e19a24088753be; imClientId_0=9e6702f76d03ac5a694a49467e3c9cd1; imId_0=9e6702f76d03ac5ac0e19a24088753be; imApp_0=1; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1682508858; fe_im_socketSequence_new_0=2_2_2; __session_seq=6; __uv_seq=6; fe_im_opened_pages=; fe_im_connectJson_0=%7B%220_6f683431aef475db6bc56763ae71c6f2%22%3A%7B%22socketConnect%22%3A%222%22%2C%22connectDomain%22%3A%22liepin.com%22%7D%7D; _ga_54YTJKWN86=GS1.1.1682508702.3.1.1682508884.0.0.0',\n",
    "    'Host': 'apic.liepin.com',\n",
    "    'Origin': 'https://www.liepin.com',\n",
    "    'Pragma': 'no-cache',\n",
    "    'Referer': 'https://www.liepin.com/',\n",
    "    'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"',\n",
    "    'sec-ch-ua-mobile': '?0',\n",
    "    'sec-ch-ua-platform': '\"macOS\"',\n",
    "    'Sec-Fetch-Dest': 'empty',\n",
    "    'Sec-Fetch-Mode': 'cors',\n",
    "    'Sec-Fetch-Site': 'same-site',\n",
    "    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36',\n",
    "    'X-Client-Type': 'web',\n",
    "    'X-Fscp-Bi-Stat': '{\"location\": \"https://www.liepin.com/zhaopin/?inputFrom=www_index&workYearCode=0&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&scene=input&ckId=htihov8m2frxgy6ywo2wsg2gncnydzlb&dq=\"}',\n",
    "    'X-Fscp-Fe-Version': '',\n",
    "    'X-Fscp-Std-Info': '{\"client_id\": \"40108\"}',\n",
    "    'X-Fscp-Trace-Id': 'ca0f2044-5eea-413c-bc5a-1ebff017261f',\n",
    "    'X-Fscp-Version': '1.1',\n",
    "    'X-Requested-With': 'XMLHttpRequest',\n",
    "    'X-XSRF-TOKEN': 'UH8huvwpTv6t6qio3oBLOQ'\n",
    "}"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "af45d2e0",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(url,data=json.dumps(payload),headers=headers)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "39a0c6bc",
   "metadata": {},
   "source": [
    "* json.dumps 把python当中的字典转换成json"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "874fbfcb",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "{'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/111.0.0.0 Safari/537.36', 'Accept-Encoding': 'gzip, deflate, br', 'Accept': 'application/json, text/plain, */*', 'Connection': 'keep-alive', 'Accept-Language': 'zh-CN,zh;q=0.9', 'Cache-Control': 'no-cache', 'Content-Length': '445', 'Content-Type': 'application/json;charset=UTF-8;', 'Cookie': 'inited_user=c8fbc4bc55b6e51a966d6a7b04560e2b; __uuid=1681904685651.21; __gc_id=dec84b24056047edae4ab20d0f3b552c; _ga=GA1.1.1262698532.1681904712; __tlog=1682508693416.34%7C00000000%7C00000000%7Cs_00_003%7Cs_00_003; XSRF-TOKEN=QPpeeqO4QQWdJqIco9nBJg; Hm_lvt_a2647413544f5a04f00da7eee0d5e200=1681904713,1682508703; acw_tc=2760829516825087007741276e1caa6c807a01cfcdc2c891680768c4e8d0e4; UniqueKey=6f683431aef475db6bc56763ae71c6f2; liepin_login_valid=0; lt_auth=7%2BlcaSMGzVnwtSXRj2MK5Kcb2Y3%2BU2jN8Stfh0xUht%2FoCPfk4P%2FmQAOHqLME%2BCoIqxkhJvUzMLb2N%2B3%2BwXRJ7kAW8FGnlpyutP2k1XYeTeVnHuyflMXuqsjQQ5wtrXo6ykpgn2si0HU%3D; access_system=C; user_roles=0; need_bind_tel=false; new_user=true; c_flag=d2d1cef45ed41589b63eda8f3d9bae3e; user_photo=5f8fa3a6f6d1ab58476f322808u.png; user_name=%E4%B8%AD%E6%96%B9%E6%B3%95; inited_user=c8fbc4bc55b6e51a966d6a7b04560e2b; imClientId=9e6702f76d03ac5a694a49467e3c9cd1; imId=9e6702f76d03ac5ac0e19a24088753be; imClientId_0=9e6702f76d03ac5a694a49467e3c9cd1; imId_0=9e6702f76d03ac5ac0e19a24088753be; imApp_0=1; Hm_lpvt_a2647413544f5a04f00da7eee0d5e200=1682508858; fe_im_socketSequence_new_0=2_2_2; __session_seq=6; __uv_seq=6; fe_im_opened_pages=; fe_im_connectJson_0=%7B%220_6f683431aef475db6bc56763ae71c6f2%22%3A%7B%22socketConnect%22%3A%222%22%2C%22connectDomain%22%3A%22liepin.com%22%7D%7D; _ga_54YTJKWN86=GS1.1.1682508702.3.1.1682508884.0.0.0', 'Host': 'apic.liepin.com', 'Origin': 'https://www.liepin.com', 'Pragma': 'no-cache', 'Referer': 'https://www.liepin.com/', 'sec-ch-ua': '\"Google Chrome\";v=\"111\", \"Not(A:Brand\";v=\"8\", \"Chromium\";v=\"111\"', 'sec-ch-ua-mobile': '?0', 'sec-ch-ua-platform': '\"macOS\"', 'Sec-Fetch-Dest': 'empty', 'Sec-Fetch-Mode': 'cors', 'Sec-Fetch-Site': 'same-site', 'X-Client-Type': 'web', 'X-Fscp-Bi-Stat': '{\"location\": \"https://www.liepin.com/zhaopin/?inputFrom=www_index&workYearCode=0&key=%E4%BA%A7%E5%93%81%E7%BB%8F%E7%90%86&scene=input&ckId=htihov8m2frxgy6ywo2wsg2gncnydzlb&dq=\"}', 'X-Fscp-Fe-Version': '', 'X-Fscp-Std-Info': '{\"client_id\": \"40108\"}', 'X-Fscp-Trace-Id': 'ca0f2044-5eea-413c-bc5a-1ebff017261f', 'X-Fscp-Version': '1.1', 'X-Requested-With': 'XMLHttpRequest', 'X-XSRF-TOKEN': 'UH8huvwpTv6t6qio3oBLOQ'}"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.request.headers"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "ba5b86b0",
   "metadata": {},
   "outputs": [],
   "source": [
    "r = requests.post(url,params=payload)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "3874ca7d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "200"
      ]
     },
     "execution_count": 25,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "r.status_code"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
